home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / applications / wp / ttx2_sasc.lha / Rexx / TTX_SASC / SafeGetFileName < prev    next >
Encoding:
Text File  |  1994-10-24  |  2.4 KB  |  80 lines

  1.  
  2. /** $VER: SafeGetFileName 1.0 (23.10.94)
  3.  **
  4.  ** SafeGetFileName: makes sure that the currently loaded file has an
  5.  ** appropriate name for the operations about to be performed.  It is
  6.  ** picky.  If the file has no name, it forces the user to save it.  If
  7.  ** the file has a name but needs saving, the user is asked if she wants
  8.  ** to continue.  And so on...
  9.  **
  10.  ** The full pathname of the file is returned to the calling context.
  11.  **
  12.  ** Written by Kenneth Yarnall.  This code may be freely distributed.
  13.  **/
  14.  
  15.  
  16. SafeGetFileName:
  17. Options RESULTS
  18.  
  19. GetFileInfo
  20. parse var RESULT . modified '"'filename'"'
  21.  
  22. /*
  23. ** We need a full filepath.  Cover all our bases
  24. */
  25.  
  26. if modified = NO & filename = "" then do    /* is there a file at all? */
  27.                                             /* no, there isn't */
  28.     RequestBool '"TTX <=> SAS/C" "Load a file to compile?"'
  29.     if RESULT = YES then do                 /* we get a fullpath this    */
  30.                                             /* way, and load it into TTX */
  31.         drop RESULT
  32.         RequestFile 'PROMPT "Load source file" PATTERN #? sc:'
  33.         fullname = RESULT
  34.         if fullname = "RESULT" then do
  35.             SetStatusBar '"No file to compile"'
  36.             exit 0              /* no file, so leave */
  37.         end
  38.         else
  39.             NOP
  40.         OpenFile fullname
  41.         GetFileInfo
  42.         parse var RESULT . . '"'filename'"'
  43.     end
  44.     else do
  45.         SetStatusBar '"No file to compile"'
  46.         exit 0                  /* no file, so leave */
  47.     end
  48. end
  49. else do                         /* yes, there is a file */
  50.     if filename = "" then do    /* but it has no name? */
  51.         drop RESULT
  52.         RequestFile 'PROMPT "Save document as..." PATTERN #? sc:'
  53.         fullname = RESULT
  54.         if fullname = "RESULT" then do
  55.             SetStatusBar '"No file to compile"'
  56.             exit 0              /* no file, so leave */
  57.         end
  58.         else
  59.             NOP
  60.         SaveFileAs fullname     /* Save the file */
  61.         SetFilePath fullname
  62.         GetFileInfo
  63.         parse var RESULT . . '"'filename'"'
  64.     end
  65.     else do                     /* File has a name */
  66.         GetFilePath
  67.         fullname = RESULT
  68.         if modified = YES then do   /* has it been modified? */
  69.             RequestBool '"TTX <=> SAS/C" "Save before compiling?"'
  70.             if RESULT = YES then
  71.                 SaveFile
  72.             else
  73.                 NOP
  74.         end
  75.     end
  76. end
  77.  
  78. Return fullname
  79.  
  80.